package com.example.hellovaadin;

import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.CustomLayout;
import com.vaadin.ui.Notification;
import com.vaadin.ui.Panel;
import com.vaadin.ui.PasswordField;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.themes.Runo;

/** A start view for navigating to the main view */
public class StartView extends VerticalLayout implements View {
    public StartView() {
        setSizeFull();
        Panel panel = new Panel("Login");		
		panel.setSizeUndefined(); // Shrink to fit content
		panel.addStyleName(Runo.PANEL_LIGHT);
		
		CustomLayout content = new CustomLayout("loginlayout");
		content.addStyleName(Runo.LAYOUT_DARKER);
		
		panel.setContent(content);
        
        
        TextField tfEmail = new TextField();	
		tfEmail.setRequired(true);
		PasswordField tfPassword = new PasswordField();
		tfPassword.setRequired(true);
		TextField tfreadonly = new TextField();
		tfreadonly.setValue("Enter your email to login");
		tfreadonly.setReadOnly(true);
        Button button = new Button("Sign in",
                new Button.ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
            	getUI().getNavigator().navigateTo(Views.MAINVIEW);
            }
        });	        
        content.addComponent(tfEmail,"username");
        content.addComponent(tfPassword,"password");
        content.addComponent(button,"okbutton");
        content.addComponent(tfreadonly);
        addComponent(panel);
        setComponentAlignment(panel, Alignment.MIDDLE_CENTER);
    }        
        
    @Override
    public void enter(ViewChangeEvent event) {
        Notification.show("Welcome to the Animal Farm");
    }
}